from django.db import models
from django.utils.timezone import now


class Mission(models.Model):
    id = models.CharField(db_column="c_id", max_length=32, verbose_name=u"主键", primary_key=True, blank=False,
                          null=False)
    key = models.CharField(db_column="c_key", max_length=32, verbose_name="网关")
    gateway_id = models.CharField(db_column="c_gateway_id", max_length=8, verbose_name="网关id", null=True)
    sensor_id = models.CharField(db_column="c_sensor_id", max_length=32, verbose_name="传感器", null=True)
    sensor_number = models.IntegerField(db_column="c_sensor_number", verbose_name="传感器编号", null=True)
    mission_number = models.IntegerField(db_column="c_mission_number", verbose_name="任务编号")
    is_again = models.BooleanField(db_column="c_is_again", verbose_name="是否已经重新执行过", default=False)
    file_path = models.CharField(max_length=200, db_column="c_file_path", verbose_name="日志文件路径")
    description = models.CharField(db_column="c_description", max_length=100, verbose_name="任务描述")
    state = models.IntegerField(db_column="c_state", verbose_name="状态", default=0)
    pct = models.IntegerField(db_column="c_pct", verbose_name="进度", default=0)
    failed_reason = models.CharField(db_column="c_failed_reason", max_length=100, verbose_name="任务失败原因", default="")
    mission_result = models.TextField(db_column="c_mission_result", verbose_name="任务结果", default="")
    is_delete = models.BooleanField(db_column="c_is_delete", default=False)
    create_date = models.DateTimeField(db_column="c_create_date", default=now)
    update_date = models.DateTimeField(db_column="c_update_date", default=now)

    class Meta:
        db_table = "t_mission"
        verbose_name = "任务表"
        verbose_name_plural = verbose_name
        ordering = ["create_date"]
